﻿using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using TeamExplorer.Merge.Base;

namespace TeamExplorer.Merge.MergeCandidates
{
    public class MergeCandidateViewModel : NotifyPropertyChangedBase
    {
        private bool _justMerged;
        
        public int ChangesetId { get; private set; }
        public bool HasPolicyFailures { get; private set; }
        public string Comment { get; private set; }
        public DateTime CreationDate { get; private set; }

        public bool JustMerged
        {
            get
            {
                return _justMerged;
            }
            set
            {
                _justMerged = value;
                RaisePropertyChanged("JustMerged");
            }
        }

        public MergeCandidateViewModel(MergeCandidate candidate)
        {
            if (candidate == null) 
                throw new ArgumentNullException("Merge candidate cannot be null");

            JustMerged = false;
            ChangesetId = candidate.Changeset.ChangesetId;
            HasPolicyFailures = candidate.Changeset.PolicyOverride.PolicyFailures.Any();
            Comment = String.IsNullOrEmpty(candidate.Changeset.Comment) ? "<no comment>" : candidate.Changeset.Comment;
            CreationDate = candidate.Changeset.CreationDate;
        }

        public MergeCandidateViewModel(int changesetId, bool hasPolicyFailures, string comment, DateTime creationDate)
        {
            if (changesetId == 0)
                throw new ArgumentNullException("Merge candidate id cannot be 0");

            ChangesetId = changesetId;
            HasPolicyFailures = hasPolicyFailures;
            Comment = comment;
            CreationDate = creationDate;
        }
    }
}
